<!DOCTYPE html>
<%@ page contentType="text/html;charset=UTF-8"  import="com.mmp.main.entity.*,java.util.* , com.mmp.main.util.*"%>
<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<% 
List<Site> siteList = (List<Site>) request.getAttribute("siteList");
boolean currentUserIsDirectorateAdmin = WebUtil.currentUserIsDirectorateAdmin(request);
%>
<script>

function getHospitalList(srcObj){
	
	$("#hospListContainer select").empty();
	 
    var siteId = $(srcObj).val(); 
    if(siteId != ""){
	    $.getJSON("ChooseSessionHospitalDisplay",{siteId: siteId}, function(data){
		    if (data.length > 0 ){
		    	
		         //$("#hospListContainer").append("<select id='hospital' name='hospital' class='auto_off' required></select>");
		         $.each(data, function (index, value) {
		        	 $("select[name='hospital']").append($('<option>').text(value.name).attr('value', value.id));
		         });
		         if (data.length > 1){	 
		        	 if (<%=currentUserIsDirectorateAdmin%>)
		            	 $("select[name='hospital'] option").eq(0).before($("<option></option>").val("0").text("الكل"));
		        	 else
		        		 $("select[name='hospital'] option").eq(0).before($("<option></option>").val("").text("من فضلك اختر"));
		             $("select[name='hospital']").prop('selectedIndex', 0);

		         }
		    }
	    });
    }
}


</script>
</head>
<body>
<form method="post" action="ChooseSessionHospitalProcess">
  <table class="layout_grid basic_page">
    <tbody>
      <tr>
        <td colspan="2"><h1 class="page_title">شاشة اختيار الموقع</h1></td>
      </tr>
      
      <%String cssClass = (currentUserIsDirectorateAdmin) ? "" : "class='auto_off'";%>
      <tr <%=(!currentUserIsDirectorateAdmin)?"style='display:none'" : "" %>>
        <td class="side_label_middle">اسم الموقع : </td>
        <td><select name="site" <%=cssClass %> onChange="getHospitalList(this)" required>
            <%
            if (siteList != null)
              for (Site obj : siteList){
             %>
            <option value="<%=obj.getId()%>"><%=obj.getName()%></option>
            <%}%>
          </select></td>
      </tr>
      <tr>
        <td class="side_label_middle">اسم المستشفى أو المركز الصحي :</td>
        <td id="hospListContainer"> <select style="min-width: 123px" id='hospital' name='hospital' class='auto_off' required><option></option></select> </td>
      </tr>
    
      <tr>
      <td>&nbsp;</td>
      <td><input type="submit" name="continue" value='متابعة' /></td>
    </tr>
  </table>
</form>

<script>
if (<%=!currentUserIsDirectorateAdmin%>){
	$("select[name='site']").change();
}
	$.removeCookie('reportType');
	$.removeCookie('reportLocation');
</script>
</body>
</html>
